
-- --------------------------------------------------
-- Entity Designer DDL Script for SQL Server 2005, 2008, and Azure
-- --------------------------------------------------
-- Date Created: 06/17/2012 20:38:42
-- Generated from EDMX file: E:\Project\Yootops\SBACN\trunk\WebSite\Models\Data.edmx
-- --------------------------------------------------

SET QUOTED_IDENTIFIER OFF;
GO
USE [SEC_BakTest];
GO
IF SCHEMA_ID(N'dbo') IS NULL EXECUTE(N'CREATE SCHEMA [dbo]');
GO

-- --------------------------------------------------
-- Dropping existing FOREIGN KEY constraints
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[FK_TB_Complaints_TB_SystemMap]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[TB_Feedback] DROP CONSTRAINT [FK_TB_Complaints_TB_SystemMap];
GO
IF OBJECT_ID(N'[dbo].[FK_TB_CouncilRelation_TB_CouncilRelation]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[TB_CouncilRelation] DROP CONSTRAINT [FK_TB_CouncilRelation_TB_CouncilRelation];
GO
IF OBJECT_ID(N'[dbo].[FK_TB_CouncilRelation_TB_Member]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[TB_CouncilRelation] DROP CONSTRAINT [FK_TB_CouncilRelation_TB_Member];
GO
IF OBJECT_ID(N'[dbo].[FK_TB_CouncilRelation_TB_SystemMap]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[TB_CouncilRelation] DROP CONSTRAINT [FK_TB_CouncilRelation_TB_SystemMap];
GO
IF OBJECT_ID(N'[dbo].[FK_TB_ExamQuota_TB_Examination]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[TB_ExamQuota] DROP CONSTRAINT [FK_TB_ExamQuota_TB_Examination];
GO
IF OBJECT_ID(N'[dbo].[FK_TB_ExamQuota_TB_Member]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[TB_ExamQuota] DROP CONSTRAINT [FK_TB_ExamQuota_TB_Member];
GO
IF OBJECT_ID(N'[dbo].[FK_TB_MediaReports_TB_MediaReports]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[TB_MediaReports] DROP CONSTRAINT [FK_TB_MediaReports_TB_MediaReports];
GO
IF OBJECT_ID(N'[dbo].[FK_TB_Member_TB_SystemMap]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[TB_Member] DROP CONSTRAINT [FK_TB_Member_TB_SystemMap];
GO
IF OBJECT_ID(N'[dbo].[FK_TB_News_TB_SystemMap]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[TB_News] DROP CONSTRAINT [FK_TB_News_TB_SystemMap];
GO
IF OBJECT_ID(N'[dbo].[FK_TB_OutLink_TB_SysDict]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[TB_OutLink] DROP CONSTRAINT [FK_TB_OutLink_TB_SysDict];
GO
IF OBJECT_ID(N'[dbo].[FK_TB_RoleRelate_TB_Role]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[TB_RoleRightRelation] DROP CONSTRAINT [FK_TB_RoleRelate_TB_Role];
GO
IF OBJECT_ID(N'[dbo].[FK_TB_RoleRightRelation_TB_AdminRight]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[TB_RoleRightRelation] DROP CONSTRAINT [FK_TB_RoleRightRelation_TB_AdminRight];
GO
IF OBJECT_ID(N'[dbo].[FK_TB_Score_TB_Examination]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[TB_Score] DROP CONSTRAINT [FK_TB_Score_TB_Examination];
GO
IF OBJECT_ID(N'[dbo].[FK_TB_Score_TB_Member]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[TB_Score] DROP CONSTRAINT [FK_TB_Score_TB_Member];
GO
IF OBJECT_ID(N'[dbo].[FK_TB_SystemConfig_TB_SysDict]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[TB_SystemConfig] DROP CONSTRAINT [FK_TB_SystemConfig_TB_SysDict];
GO
IF OBJECT_ID(N'[dbo].[FK_TB_UploadInfo_TB_SystemMap]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[TB_UploadInfo] DROP CONSTRAINT [FK_TB_UploadInfo_TB_SystemMap];
GO
IF OBJECT_ID(N'[dbo].[FK_TB_User_TB_Member]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[TB_User] DROP CONSTRAINT [FK_TB_User_TB_Member];
GO
IF OBJECT_ID(N'[dbo].[FK_TB_UserInRoles_TB_Role]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[TB_UserInRoles] DROP CONSTRAINT [FK_TB_UserInRoles_TB_Role];
GO
IF OBJECT_ID(N'[dbo].[FK_TB_UserInRoles_TB_User]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[TB_UserInRoles] DROP CONSTRAINT [FK_TB_UserInRoles_TB_User];
GO

-- --------------------------------------------------
-- Dropping existing tables
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[TB_Activities]', 'U') IS NOT NULL
    DROP TABLE [dbo].[TB_Activities];
GO
IF OBJECT_ID(N'[dbo].[TB_CouncilInfo]', 'U') IS NOT NULL
    DROP TABLE [dbo].[TB_CouncilInfo];
GO
IF OBJECT_ID(N'[dbo].[TB_CouncilRelation]', 'U') IS NOT NULL
    DROP TABLE [dbo].[TB_CouncilRelation];
GO
IF OBJECT_ID(N'[dbo].[TB_Examination]', 'U') IS NOT NULL
    DROP TABLE [dbo].[TB_Examination];
GO
IF OBJECT_ID(N'[dbo].[TB_ExamQuota]', 'U') IS NOT NULL
    DROP TABLE [dbo].[TB_ExamQuota];
GO
IF OBJECT_ID(N'[dbo].[TB_Feedback]', 'U') IS NOT NULL
    DROP TABLE [dbo].[TB_Feedback];
GO
IF OBJECT_ID(N'[dbo].[TB_MediaReports]', 'U') IS NOT NULL
    DROP TABLE [dbo].[TB_MediaReports];
GO
IF OBJECT_ID(N'[dbo].[TB_Member]', 'U') IS NOT NULL
    DROP TABLE [dbo].[TB_Member];
GO
IF OBJECT_ID(N'[dbo].[TB_MonthlyEvents]', 'U') IS NOT NULL
    DROP TABLE [dbo].[TB_MonthlyEvents];
GO
IF OBJECT_ID(N'[dbo].[TB_News]', 'U') IS NOT NULL
    DROP TABLE [dbo].[TB_News];
GO
IF OBJECT_ID(N'[dbo].[TB_OutLink]', 'U') IS NOT NULL
    DROP TABLE [dbo].[TB_OutLink];
GO
IF OBJECT_ID(N'[dbo].[TB_Professional]', 'U') IS NOT NULL
    DROP TABLE [dbo].[TB_Professional];
GO
IF OBJECT_ID(N'[dbo].[TB_PublicUser]', 'U') IS NOT NULL
    DROP TABLE [dbo].[TB_PublicUser];
GO
IF OBJECT_ID(N'[dbo].[TB_Role]', 'U') IS NOT NULL
    DROP TABLE [dbo].[TB_Role];
GO
IF OBJECT_ID(N'[dbo].[TB_RoleRightRelation]', 'U') IS NOT NULL
    DROP TABLE [dbo].[TB_RoleRightRelation];
GO
IF OBJECT_ID(N'[dbo].[TB_Score]', 'U') IS NOT NULL
    DROP TABLE [dbo].[TB_Score];
GO
IF OBJECT_ID(N'[dbo].[TB_SystemConfig]', 'U') IS NOT NULL
    DROP TABLE [dbo].[TB_SystemConfig];
GO
IF OBJECT_ID(N'[dbo].[TB_SystemMap]', 'U') IS NOT NULL
    DROP TABLE [dbo].[TB_SystemMap];
GO
IF OBJECT_ID(N'[dbo].[TB_UploadInfo]', 'U') IS NOT NULL
    DROP TABLE [dbo].[TB_UploadInfo];
GO
IF OBJECT_ID(N'[dbo].[TB_User]', 'U') IS NOT NULL
    DROP TABLE [dbo].[TB_User];
GO
IF OBJECT_ID(N'[dbo].[TB_UserInRoles]', 'U') IS NOT NULL
    DROP TABLE [dbo].[TB_UserInRoles];
GO
IF OBJECT_ID(N'[SBACNModelsStoreContainer].[View_UserRightList]', 'U') IS NOT NULL
    DROP TABLE [SBACNModelsStoreContainer].[View_UserRightList];
GO

-- --------------------------------------------------
-- Creating all tables
-- --------------------------------------------------

-- Creating table 'TB_CouncilInfo'
CREATE TABLE [dbo].[TB_CouncilInfo] (
    [Index] int  NOT NULL,
    [Name] nvarchar(50)  NOT NULL,
    [StartTime] datetime  NOT NULL,
    [EndTime] datetime  NULL,
    [Memo] nvarchar(500)  NULL,
    [Status] bit  NOT NULL,
    [CreateBy] nvarchar(50)  NOT NULL,
    [CreateDate] datetime  NOT NULL,
    [EnName] nvarchar(200)  NULL,
    [EnMemo] nvarchar(2000)  NULL
);
GO

-- Creating table 'TB_CouncilRelation'
CREATE TABLE [dbo].[TB_CouncilRelation] (
    [ID] int  NOT NULL,
    [Index] int  NOT NULL,
    [Type] nvarchar(50)  NOT NULL,
    [MemberID] int  NOT NULL
);
GO

-- Creating table 'TB_Examination'
CREATE TABLE [dbo].[TB_Examination] (
    [ID] int IDENTITY(1,1) NOT NULL,
    [Subject] nvarchar(50)  NOT NULL,
    [StartDate] datetime  NOT NULL,
    [EndDate] datetime  NULL,
    [IsTrain] bit  NOT NULL,
    [Deadline] datetime  NOT NULL,
    [Memo] nvarchar(2000)  NULL,
    [FilePathJson] nvarchar(max)  NULL,
    [Status] int  NOT NULL,
    [CreateBy] nvarchar(50)  NULL,
    [CreateDate] datetime  NOT NULL
);
GO

-- Creating table 'TB_ExamQuota'
CREATE TABLE [dbo].[TB_ExamQuota] (
    [ID] int IDENTITY(1,1) NOT NULL,
    [ExamID] int  NOT NULL,
    [MemberID] int  NOT NULL,
    [Count] int  NOT NULL
);
GO

-- Creating table 'TB_Member'
CREATE TABLE [dbo].[TB_Member] (
    [ID] int IDENTITY(1,1) NOT NULL,
    [Name] nvarchar(500)  NOT NULL,
    [Type] nvarchar(50)  NOT NULL,
    [Address] nvarchar(500)  NULL,
    [Telephone] nvarchar(50)  NULL,
    [Fax] nvarchar(50)  NULL,
    [ContractPersonName] nvarchar(50)  NULL,
    [EMail] nvarchar(100)  NULL,
    [WebSite] nvarchar(200)  NULL,
    [LogoUrl] nvarchar(200)  NULL,
    [Description] nvarchar(500)  NULL,
    [Status] bit  NOT NULL,
    [SortIndex] int  NOT NULL,
    [EnName] nvarchar(1000)  NULL,
    [EnAddress] nvarchar(1000)  NULL,
    [ContractPersonEnName] nvarchar(200)  NULL,
    [EnDescription] nvarchar(2000)  NULL
);
GO

-- Creating table 'TB_News'
CREATE TABLE [dbo].[TB_News] (
    [ID] int IDENTITY(1,1) NOT NULL,
    [Type] nvarchar(50)  NOT NULL,
    [Title] nvarchar(100)  NOT NULL,
    [Summary] nvarchar(500)  NULL,
    [Content] nvarchar(max)  NULL,
    [ReadCount] int  NOT NULL,
    [IsImageNews] bit  NOT NULL,
    [IsAutoScorllNews] bit  NOT NULL,
    [IsEn] bit  NOT NULL,
    [IsPrivate] bit  NOT NULL,
    [MainImageUrl] nvarchar(200)  NULL,
    [AttachmentsJosnUrl] nvarchar(max)  NULL,
    [CreateDate] datetime  NOT NULL,
    [CreateBy] nvarchar(50)  NULL
);
GO

-- Creating table 'TB_OutLink'
CREATE TABLE [dbo].[TB_OutLink] (
    [ID] int IDENTITY(1,1) NOT NULL,
    [LinkName] nvarchar(50)  NOT NULL,
    [LinkUrl] nvarchar(500)  NULL,
    [ImageLink] bit  NOT NULL,
    [ImageUrl] nvarchar(200)  NULL,
    [Type] nvarchar(50)  NOT NULL,
    [Status] bit  NOT NULL,
    [CreateBy] nvarchar(50)  NULL,
    [CreateDate] datetime  NOT NULL
);
GO

-- Creating table 'TB_Role'
CREATE TABLE [dbo].[TB_Role] (
    [ID] int IDENTITY(1,1) NOT NULL,
    [Name] nvarchar(50)  NOT NULL,
    [Status] bit  NOT NULL,
    [Description] nvarchar(500)  NULL,
    [Editable] bit  NOT NULL
);
GO

-- Creating table 'TB_Score'
CREATE TABLE [dbo].[TB_Score] (
    [ID] int IDENTITY(1,1) NOT NULL,
    [ExamID] int  NOT NULL,
    [MemberID] int  NOT NULL,
    [Name] nvarchar(50)  NOT NULL,
    [IDCardNO] nvarchar(50)  NOT NULL,
    [Score] nvarchar(50)  NULL
);
GO

-- Creating table 'TB_SystemConfig'
CREATE TABLE [dbo].[TB_SystemConfig] (
    [ID] int IDENTITY(1,1) NOT NULL,
    [Name] nvarchar(50)  NOT NULL,
    [Code] nvarchar(50)  NOT NULL,
    [Value] nvarchar(500)  NOT NULL,
    [Type] nvarchar(50)  NOT NULL,
    [Status] bit  NOT NULL,
    [Editable] bit  NOT NULL
);
GO

-- Creating table 'TB_SystemMap'
CREATE TABLE [dbo].[TB_SystemMap] (
    [Code] nvarchar(50)  NOT NULL,
    [Name] nvarchar(50)  NOT NULL,
    [CText] nvarchar(50)  NOT NULL,
    [EText] nvarchar(50)  NULL,
    [SortIndex] int  NOT NULL,
    [CURL] nvarchar(200)  NULL,
    [EURL] nvarchar(200)  NULL,
    [ShowInMap] bit  NOT NULL,
    [Status] bit  NOT NULL,
    [AdminURL] nvarchar(200)  NULL,
    [IsAdminRight] bit  NOT NULL,
    [Description] nvarchar(500)  NULL,
    [OpenInNewWindow] bit  NOT NULL
);
GO

-- Creating table 'TB_UploadInfo'
CREATE TABLE [dbo].[TB_UploadInfo] (
    [ID] int IDENTITY(1,1) NOT NULL,
    [Name] nvarchar(50)  NOT NULL,
    [FilePath] nvarchar(200)  NULL,
    [FileType] nchar(10)  NULL,
    [PrimaryID] int  NULL,
    [SecondID] int  NULL,
    [Type] nvarchar(50)  NULL,
    [CreateBy] nvarchar(50)  NULL,
    [CreateDate] datetime  NOT NULL
);
GO

-- Creating table 'TB_User'
CREATE TABLE [dbo].[TB_User] (
    [UserName] nvarchar(50)  NOT NULL,
    [Password] nvarchar(50)  NOT NULL,
    [EMail] nvarchar(50)  NULL,
    [MemberID] int  NULL,
    [Status] bit  NOT NULL,
    [LastLoginTime] datetime  NULL,
    [LastLoginIP] nvarchar(50)  NULL,
    [LoginTime] datetime  NULL,
    [LoginIP] nvarchar(50)  NULL,
    [CreateDate] datetime  NOT NULL,
    [CreateBy] nvarchar(50)  NULL,
    [LogOutRawUrl] nvarchar(100)  NULL,
    [LoginCount] int  NOT NULL,
    [NickName] nvarchar(50)  NULL
);
GO

-- Creating table 'TB_UserInRoles'
CREATE TABLE [dbo].[TB_UserInRoles] (
    [RID] int IDENTITY(1,1) NOT NULL,
    [UserName] nvarchar(50)  NOT NULL,
    [RoleID] int  NOT NULL
);
GO

-- Creating table 'TB_Feedback'
CREATE TABLE [dbo].[TB_Feedback] (
    [ID] int IDENTITY(1,1) NOT NULL,
    [UserIdentity] nvarchar(100)  NOT NULL,
    [Title] nvarchar(100)  NOT NULL,
    [Content] nvarchar(max)  NULL,
    [Status] int  NOT NULL,
    [CreateDate] datetime  NOT NULL,
    [Type] nvarchar(50)  NOT NULL
);
GO

-- Creating table 'TB_PublicUser'
CREATE TABLE [dbo].[TB_PublicUser] (
    [EMail] nvarchar(100)  NOT NULL,
    [Name] nvarchar(50)  NOT NULL,
    [Telephone] nvarchar(50)  NOT NULL,
    [CreateDate] datetime  NOT NULL,
    [ValidCode] nvarchar(50)  NOT NULL,
    [ValidDate] datetime  NULL,
    [Satus] bit  NOT NULL
);
GO

-- Creating table 'TB_Activities'
CREATE TABLE [dbo].[TB_Activities] (
    [ID] int IDENTITY(1,1) NOT NULL,
    [Title] nvarchar(100)  NOT NULL,
    [Address] nvarchar(100)  NOT NULL,
    [Description] nvarchar(500)  NULL,
    [ActivitiesDate] datetime  NOT NULL,
    [CreateDate] datetime  NOT NULL,
    [CreateBy] nvarchar(50)  NULL
);
GO

-- Creating table 'TB_MediaReports'
CREATE TABLE [dbo].[TB_MediaReports] (
    [ID] int IDENTITY(1,1) NOT NULL,
    [ActivityID] int  NOT NULL,
    [MediaName] nvarchar(100)  NOT NULL,
    [Title] nvarchar(100)  NOT NULL,
    [Description] nvarchar(500)  NULL,
    [ReportDate] datetime  NOT NULL,
    [SourceURL] nvarchar(200)  NULL,
    [SnapPic] nvarchar(200)  NULL,
    [CreateDate] datetime  NOT NULL,
    [CreateBy] nvarchar(50)  NULL
);
GO

-- Creating table 'TB_MonthlyEvents'
CREATE TABLE [dbo].[TB_MonthlyEvents] (
    [ID] int IDENTITY(1,1) NOT NULL,
    [Title] nvarchar(50)  NOT NULL,
    [Description] nvarchar(200)  NULL,
    [EventDate] datetime  NOT NULL,
    [Address] nvarchar(100)  NULL,
    [CreateDate] datetime  NOT NULL,
    [CreateBy] nvarchar(50)  NULL,
    [StartHour] int  NOT NULL,
    [EndHour] int  NOT NULL
);
GO

-- Creating table 'TB_RoleRightRelation'
CREATE TABLE [dbo].[TB_RoleRightRelation] (
    [RID] int IDENTITY(1,1) NOT NULL,
    [RoleID] int  NOT NULL,
    [Code] nvarchar(50)  NOT NULL,
    [Type] bit  NOT NULL
);
GO

-- Creating table 'View_UserRightList'
CREATE TABLE [dbo].[View_UserRightList] (
    [UserName] nvarchar(50)  NOT NULL,
    [URL] nvarchar(200)  NULL,
    [Type] bit  NOT NULL
);
GO

-- Creating table 'TB_Professional'
CREATE TABLE [dbo].[TB_Professional] (
    [ID] int IDENTITY(1,1) NOT NULL,
    [Type] nvarchar(50)  NOT NULL,
    [Name] nvarchar(50)  NULL,
    [Contract] nvarchar(100)  NULL,
    [Level] nvarchar(50)  NULL
);
GO

-- --------------------------------------------------
-- Creating all PRIMARY KEY constraints
-- --------------------------------------------------

-- Creating primary key on [Index] in table 'TB_CouncilInfo'
ALTER TABLE [dbo].[TB_CouncilInfo]
ADD CONSTRAINT [PK_TB_CouncilInfo]
    PRIMARY KEY CLUSTERED ([Index] ASC);
GO

-- Creating primary key on [ID] in table 'TB_CouncilRelation'
ALTER TABLE [dbo].[TB_CouncilRelation]
ADD CONSTRAINT [PK_TB_CouncilRelation]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [ID] in table 'TB_Examination'
ALTER TABLE [dbo].[TB_Examination]
ADD CONSTRAINT [PK_TB_Examination]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [ID] in table 'TB_ExamQuota'
ALTER TABLE [dbo].[TB_ExamQuota]
ADD CONSTRAINT [PK_TB_ExamQuota]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [ID] in table 'TB_Member'
ALTER TABLE [dbo].[TB_Member]
ADD CONSTRAINT [PK_TB_Member]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [ID] in table 'TB_News'
ALTER TABLE [dbo].[TB_News]
ADD CONSTRAINT [PK_TB_News]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [ID] in table 'TB_OutLink'
ALTER TABLE [dbo].[TB_OutLink]
ADD CONSTRAINT [PK_TB_OutLink]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [ID] in table 'TB_Role'
ALTER TABLE [dbo].[TB_Role]
ADD CONSTRAINT [PK_TB_Role]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [ID] in table 'TB_Score'
ALTER TABLE [dbo].[TB_Score]
ADD CONSTRAINT [PK_TB_Score]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [ID] in table 'TB_SystemConfig'
ALTER TABLE [dbo].[TB_SystemConfig]
ADD CONSTRAINT [PK_TB_SystemConfig]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [Code] in table 'TB_SystemMap'
ALTER TABLE [dbo].[TB_SystemMap]
ADD CONSTRAINT [PK_TB_SystemMap]
    PRIMARY KEY CLUSTERED ([Code] ASC);
GO

-- Creating primary key on [ID] in table 'TB_UploadInfo'
ALTER TABLE [dbo].[TB_UploadInfo]
ADD CONSTRAINT [PK_TB_UploadInfo]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [UserName] in table 'TB_User'
ALTER TABLE [dbo].[TB_User]
ADD CONSTRAINT [PK_TB_User]
    PRIMARY KEY CLUSTERED ([UserName] ASC);
GO

-- Creating primary key on [RID] in table 'TB_UserInRoles'
ALTER TABLE [dbo].[TB_UserInRoles]
ADD CONSTRAINT [PK_TB_UserInRoles]
    PRIMARY KEY CLUSTERED ([RID] ASC);
GO

-- Creating primary key on [ID] in table 'TB_Feedback'
ALTER TABLE [dbo].[TB_Feedback]
ADD CONSTRAINT [PK_TB_Feedback]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [EMail] in table 'TB_PublicUser'
ALTER TABLE [dbo].[TB_PublicUser]
ADD CONSTRAINT [PK_TB_PublicUser]
    PRIMARY KEY CLUSTERED ([EMail] ASC);
GO

-- Creating primary key on [ID] in table 'TB_Activities'
ALTER TABLE [dbo].[TB_Activities]
ADD CONSTRAINT [PK_TB_Activities]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [ID] in table 'TB_MediaReports'
ALTER TABLE [dbo].[TB_MediaReports]
ADD CONSTRAINT [PK_TB_MediaReports]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [ID] in table 'TB_MonthlyEvents'
ALTER TABLE [dbo].[TB_MonthlyEvents]
ADD CONSTRAINT [PK_TB_MonthlyEvents]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [RID] in table 'TB_RoleRightRelation'
ALTER TABLE [dbo].[TB_RoleRightRelation]
ADD CONSTRAINT [PK_TB_RoleRightRelation]
    PRIMARY KEY CLUSTERED ([RID] ASC);
GO

-- Creating primary key on [UserName], [Type] in table 'View_UserRightList'
ALTER TABLE [dbo].[View_UserRightList]
ADD CONSTRAINT [PK_View_UserRightList]
    PRIMARY KEY CLUSTERED ([UserName], [Type] ASC);
GO

-- Creating primary key on [ID] in table 'TB_Professional'
ALTER TABLE [dbo].[TB_Professional]
ADD CONSTRAINT [PK_TB_Professional]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- --------------------------------------------------
-- Creating all FOREIGN KEY constraints
-- --------------------------------------------------

-- Creating foreign key on [Index] in table 'TB_CouncilRelation'
ALTER TABLE [dbo].[TB_CouncilRelation]
ADD CONSTRAINT [FK_TB_CouncilRelation_TB_CouncilRelation]
    FOREIGN KEY ([Index])
    REFERENCES [dbo].[TB_CouncilInfo]
        ([Index])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_TB_CouncilRelation_TB_CouncilRelation'
CREATE INDEX [IX_FK_TB_CouncilRelation_TB_CouncilRelation]
ON [dbo].[TB_CouncilRelation]
    ([Index]);
GO

-- Creating foreign key on [MemberID] in table 'TB_CouncilRelation'
ALTER TABLE [dbo].[TB_CouncilRelation]
ADD CONSTRAINT [FK_TB_CouncilRelation_TB_Member]
    FOREIGN KEY ([MemberID])
    REFERENCES [dbo].[TB_Member]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_TB_CouncilRelation_TB_Member'
CREATE INDEX [IX_FK_TB_CouncilRelation_TB_Member]
ON [dbo].[TB_CouncilRelation]
    ([MemberID]);
GO

-- Creating foreign key on [ExamID] in table 'TB_ExamQuota'
ALTER TABLE [dbo].[TB_ExamQuota]
ADD CONSTRAINT [FK_TB_ExamQuota_TB_Examination]
    FOREIGN KEY ([ExamID])
    REFERENCES [dbo].[TB_Examination]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_TB_ExamQuota_TB_Examination'
CREATE INDEX [IX_FK_TB_ExamQuota_TB_Examination]
ON [dbo].[TB_ExamQuota]
    ([ExamID]);
GO

-- Creating foreign key on [ExamID] in table 'TB_Score'
ALTER TABLE [dbo].[TB_Score]
ADD CONSTRAINT [FK_TB_Score_TB_Examination]
    FOREIGN KEY ([ExamID])
    REFERENCES [dbo].[TB_Examination]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_TB_Score_TB_Examination'
CREATE INDEX [IX_FK_TB_Score_TB_Examination]
ON [dbo].[TB_Score]
    ([ExamID]);
GO

-- Creating foreign key on [MemberID] in table 'TB_ExamQuota'
ALTER TABLE [dbo].[TB_ExamQuota]
ADD CONSTRAINT [FK_TB_ExamQuota_TB_Member]
    FOREIGN KEY ([MemberID])
    REFERENCES [dbo].[TB_Member]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_TB_ExamQuota_TB_Member'
CREATE INDEX [IX_FK_TB_ExamQuota_TB_Member]
ON [dbo].[TB_ExamQuota]
    ([MemberID]);
GO

-- Creating foreign key on [Type] in table 'TB_Member'
ALTER TABLE [dbo].[TB_Member]
ADD CONSTRAINT [FK_TB_Member_TB_SystemMap]
    FOREIGN KEY ([Type])
    REFERENCES [dbo].[TB_SystemMap]
        ([Code])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_TB_Member_TB_SystemMap'
CREATE INDEX [IX_FK_TB_Member_TB_SystemMap]
ON [dbo].[TB_Member]
    ([Type]);
GO

-- Creating foreign key on [MemberID] in table 'TB_Score'
ALTER TABLE [dbo].[TB_Score]
ADD CONSTRAINT [FK_TB_Score_TB_Member]
    FOREIGN KEY ([MemberID])
    REFERENCES [dbo].[TB_Member]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_TB_Score_TB_Member'
CREATE INDEX [IX_FK_TB_Score_TB_Member]
ON [dbo].[TB_Score]
    ([MemberID]);
GO

-- Creating foreign key on [MemberID] in table 'TB_User'
ALTER TABLE [dbo].[TB_User]
ADD CONSTRAINT [FK_TB_User_TB_Member]
    FOREIGN KEY ([MemberID])
    REFERENCES [dbo].[TB_Member]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_TB_User_TB_Member'
CREATE INDEX [IX_FK_TB_User_TB_Member]
ON [dbo].[TB_User]
    ([MemberID]);
GO

-- Creating foreign key on [Type] in table 'TB_News'
ALTER TABLE [dbo].[TB_News]
ADD CONSTRAINT [FK_TB_News_TB_SysDict]
    FOREIGN KEY ([Type])
    REFERENCES [dbo].[TB_SystemMap]
        ([Code])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_TB_News_TB_SysDict'
CREATE INDEX [IX_FK_TB_News_TB_SysDict]
ON [dbo].[TB_News]
    ([Type]);
GO

-- Creating foreign key on [Type] in table 'TB_OutLink'
ALTER TABLE [dbo].[TB_OutLink]
ADD CONSTRAINT [FK_TB_OutLink_TB_SysDict]
    FOREIGN KEY ([Type])
    REFERENCES [dbo].[TB_SystemMap]
        ([Code])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_TB_OutLink_TB_SysDict'
CREATE INDEX [IX_FK_TB_OutLink_TB_SysDict]
ON [dbo].[TB_OutLink]
    ([Type]);
GO

-- Creating foreign key on [RoleID] in table 'TB_UserInRoles'
ALTER TABLE [dbo].[TB_UserInRoles]
ADD CONSTRAINT [FK_TB_UserInRoles_TB_Role]
    FOREIGN KEY ([RoleID])
    REFERENCES [dbo].[TB_Role]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_TB_UserInRoles_TB_Role'
CREATE INDEX [IX_FK_TB_UserInRoles_TB_Role]
ON [dbo].[TB_UserInRoles]
    ([RoleID]);
GO

-- Creating foreign key on [Type] in table 'TB_SystemConfig'
ALTER TABLE [dbo].[TB_SystemConfig]
ADD CONSTRAINT [FK_TB_SystemConfig_TB_SysDict]
    FOREIGN KEY ([Type])
    REFERENCES [dbo].[TB_SystemMap]
        ([Code])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_TB_SystemConfig_TB_SysDict'
CREATE INDEX [IX_FK_TB_SystemConfig_TB_SysDict]
ON [dbo].[TB_SystemConfig]
    ([Type]);
GO

-- Creating foreign key on [Type] in table 'TB_UploadInfo'
ALTER TABLE [dbo].[TB_UploadInfo]
ADD CONSTRAINT [FK_TB_UploadInfo_TB_SystemMap]
    FOREIGN KEY ([Type])
    REFERENCES [dbo].[TB_SystemMap]
        ([Code])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_TB_UploadInfo_TB_SystemMap'
CREATE INDEX [IX_FK_TB_UploadInfo_TB_SystemMap]
ON [dbo].[TB_UploadInfo]
    ([Type]);
GO

-- Creating foreign key on [UserName] in table 'TB_UserInRoles'
ALTER TABLE [dbo].[TB_UserInRoles]
ADD CONSTRAINT [FK_TB_UserInRoles_TB_User]
    FOREIGN KEY ([UserName])
    REFERENCES [dbo].[TB_User]
        ([UserName])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_TB_UserInRoles_TB_User'
CREATE INDEX [IX_FK_TB_UserInRoles_TB_User]
ON [dbo].[TB_UserInRoles]
    ([UserName]);
GO

-- Creating foreign key on [Type] in table 'TB_Feedback'
ALTER TABLE [dbo].[TB_Feedback]
ADD CONSTRAINT [FK_TB_Complaints_TB_SystemMap]
    FOREIGN KEY ([Type])
    REFERENCES [dbo].[TB_SystemMap]
        ([Code])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_TB_Complaints_TB_SystemMap'
CREATE INDEX [IX_FK_TB_Complaints_TB_SystemMap]
ON [dbo].[TB_Feedback]
    ([Type]);
GO

-- Creating foreign key on [ActivityID] in table 'TB_MediaReports'
ALTER TABLE [dbo].[TB_MediaReports]
ADD CONSTRAINT [FK_TB_MediaReports_TB_MediaReports]
    FOREIGN KEY ([ActivityID])
    REFERENCES [dbo].[TB_Activities]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_TB_MediaReports_TB_MediaReports'
CREATE INDEX [IX_FK_TB_MediaReports_TB_MediaReports]
ON [dbo].[TB_MediaReports]
    ([ActivityID]);
GO

-- Creating foreign key on [Type] in table 'TB_CouncilRelation'
ALTER TABLE [dbo].[TB_CouncilRelation]
ADD CONSTRAINT [FK_TB_CouncilRelation_TB_SystemMap]
    FOREIGN KEY ([Type])
    REFERENCES [dbo].[TB_SystemMap]
        ([Code])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_TB_CouncilRelation_TB_SystemMap'
CREATE INDEX [IX_FK_TB_CouncilRelation_TB_SystemMap]
ON [dbo].[TB_CouncilRelation]
    ([Type]);
GO

-- Creating foreign key on [RoleID] in table 'TB_RoleRightRelation'
ALTER TABLE [dbo].[TB_RoleRightRelation]
ADD CONSTRAINT [FK_TB_RoleRelate_TB_Role]
    FOREIGN KEY ([RoleID])
    REFERENCES [dbo].[TB_Role]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_TB_RoleRelate_TB_Role'
CREATE INDEX [IX_FK_TB_RoleRelate_TB_Role]
ON [dbo].[TB_RoleRightRelation]
    ([RoleID]);
GO

-- Creating foreign key on [Code] in table 'TB_RoleRightRelation'
ALTER TABLE [dbo].[TB_RoleRightRelation]
ADD CONSTRAINT [FK_TB_RoleRightRelation_TB_AdminRight]
    FOREIGN KEY ([Code])
    REFERENCES [dbo].[TB_SystemMap]
        ([Code])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_TB_RoleRightRelation_TB_AdminRight'
CREATE INDEX [IX_FK_TB_RoleRightRelation_TB_AdminRight]
ON [dbo].[TB_RoleRightRelation]
    ([Code]);
GO

-- --------------------------------------------------
-- Script has ended
-- --------------------------------------------------